class ContentController < ApplicationController
  # GET /documents
  # GET /documents.xml
  def index
    respond_to do |format|      
      format.json {
        if params[:category] != nil          
          @category = Category.find(params[:category])
          if @category != nil && @current_account.categories.member?(@category)
            @content = Content.where(:category_id => params[:category]).order("created_at desc").first
            render :json => @content
          end
        end
      }
    end
  end

  def save
    respond_to do |format|
        format.js {
            if params[:category_id]
                @content = Content.where(:category_id => params[:category_id]).order("created_at desc").first
                @content.title = params[:title]
                @content.body = params[:body]
                @content.save
            end
            render :text => ""
        }
    end
  end
end
